<template>
    <div>
        <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>车间基础建模</el-breadcrumb-item>
        <el-breadcrumb-item>工艺路线</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card>
        <el-row :gutter="10">
            <el-col span="4">
                <el-button type="primary" icon="el-icon-plus" @click="addDialogVisible = true">新增</el-button>
            </el-col>
        </el-row>
        <!-- 表格区域 -->
        <el-table stripe border
        ref="multipleTable"
        :data="routeList"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange">
    <el-table-column prop="id" label="id" width="120" align="center">
    </el-table-column>
    <el-table-column prop="siteBo" label="站点" width="195" align="center">
    </el-table-column>
    <el-table-column prop="process_route" label="工艺路线" width="195" align="center">
    </el-table-column>
    <el-table-column prop="process_route_desc" label="工艺路线描述" width="195" align="center">
    </el-table-column>
    <el-table-column label="状态" width="160" align="center">
      <template #default="scope">
            {{isOnline(scope.row.state)}}
      </template>
    </el-table-column>
    <el-table-column prop="allowpass" label="是否允许跳过" width="160" align="center">
    </el-table-column>
    <el-table-column prop="createTime" label="创建时间" width="260" align="center">
      <template #default="scope">
            {{formatDate(scope.row.createTime)}}
      </template>
    </el-table-column>
    <el-table-column prop="createUser" label="创建人" width="190" align="center">
    </el-table-column>
    <el-table-column label="操作" width="120" align="center" fixed="right">
      <template #default="scope">
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="editDialog(scope.row)"></el-button>
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="del(scope.row)"></el-button>
      </template>
    </el-table-column>
  </el-table>
  <!-- 分页区域 -->
   <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[1, 2, 5, 10]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="rowCount">
    </el-pagination>
    </el-card>
    <!-- 添加对话框 -->
    <el-dialog title="新增" v-model="addDialogVisible" width="40%">
      <!-- 对话框内容 -->
      <el-form
        :model="addForm"
        status-icon
        :rules="addFormrules"
        ref="addFormRef"
        label-width="120px"
      >
        <el-form-item label="工艺路线" prop="process_route">
          <el-input v-model="addForm.process_route" placeholder="请输入工艺路线"></el-input>
        </el-form-item>
        <el-form-item label="工艺路线描述" prop="process_route_desc">
          <el-input v-model="addForm.process_route_desc" placeholder="请输入工艺路线描述"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-select
            v-model="addForm.state"
            placeholder="请选择状态"
            
          >
            <el-option label="是" value="1"></el-option>
            <el-option label="否" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否允许跳过" prop="allowpass">
          <el-select
            v-model="addForm.allowpass"
            placeholder="是否允许跳过"
            
          >
            <el-option label="不跳过" value="1"></el-option>
            <el-option label="跳过" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工艺路线" prop="data">
          <el-select v-model="addForm.data" multiple placeholder="请选择工艺路线">
            <el-option
              v-for="item in tail"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="addDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="add">确 定</el-button>
        </span>
      </template>
    </el-dialog>
    <!-- 编辑对话框 -->
    <el-dialog title="编辑" v-model="editDialogVisible" width="40%">
      <!-- 对话框内容 -->
      <el-form
        :model="editForm"
        status-icon
        :rules="addFormrules"
        ref="editFormRef"
        label-width="120px"
      >
        <el-form-item label="工艺路线" prop="process_route">
          <el-input v-model="editForm.process_route" placeholder="请输入工艺路线"></el-input>
        </el-form-item>
        <el-form-item label="工艺路线描述" prop="process_route_desc">
          <el-input v-model="editForm.process_route_desc" placeholder="请输入工艺路线描述"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-select
            v-model="editForm.state"
            placeholder="请选择状态"
            
          >
            <el-option label="是" value="1"></el-option>
            <el-option label="否" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否允许跳过" prop="allowpass">
          <el-select
            v-model="editForm.allowpass"
            placeholder="是否允许跳过"
            
          >
            <el-option label="不跳过" value="1"></el-option>
            <el-option label="跳过" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工艺路线" prop="data">
          <el-select v-model="editForm.data" multiple placeholder="请选择工艺路线">
            <el-option
              v-for="item in tail"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="editDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="edit">确 定</el-button>
        </span>
      </template>
    </el-dialog>
    </div>
</template>

<script>
import axios from 'axios'
export default {
  data () {
    return {
      pageCount:1,
      pageNow:1,
      pageSize:10,
      rowCount:0,
      routeList:[],
      // 显示添加对话框
      addDialogVisible: false,
      // 显示编辑对话框
      editDialogVisible: false,
      addForm: {
        process_route: "",
        process_route_desc: "",
        state: "",
        allowpass: "",
        data:[],
      },
      editForm: {},
      addFormrules: {
        process_route: [
          {
            required: true,
            message: "请输入工艺路线",
            trigger: "blur",
          },
        ],
        operation_description: [
          {
            required: true,
            message: "请输入工艺路线描述",
            trigger: "blur",
          },
        ],
        state: [
          {
            required: true,
            message: "请选择状态",
            trigger: "blur",
          },
        ],
        allowpass: [
          {
            required: true,
            message: "请选择是否跳过",
            trigger: "blur",
          },
        ],
        data: [
          {
            required: true,
            message: "请选择工艺路线",
            trigger: "blur",
          },
        ],
      },
      // 工艺路线选择
      tail: [{
          value: '装配工序',
          label: '装配工序'
        }, {
          value: '测试工序',
          label: '测试工序'
        }, {
          value: '包装工序',
          label: '包装工序'
        }, {
          value: '集成测试工序',
          label: '集成测试工序'
        }, {
          value: '焊接',
          label: '焊接'
        }, {
          value: '封胶工序',
          label: '封胶工序'
        }, {
          value: '加酸工序',
          label: '加酸工序'
        }, {
          value: '清洗工序',
          label: '清洗工序'
        }, {
          value: '入库工序',
          label: '入库工序'
        }],
    }
  },
  mounted () {
    this.getList()
    
  },
  methods: {
    getList() {
    let fromdata = new FormData();
    fromdata.append("pageSize",this.pageSize)
    fromdata.append("pageNow",this.pageNow)
    axios.post('/IE_MES/workshop/routing_findByPage.shtml?site=123',fromdata).then(
      res => {
        console.log(res.data.records);
        this.routeList = res.data.records
        this.pageCount = res.data.pageCount
        this.pageNow = res.data.pageNow
        this.pageSize = res.data.pageSize
        this.rowCount = res.data.rowCount
      }
    )
    },
     // 新增
    add() {
      this.$axios({
            headers: {
              "Content-Type":
                "application/x-www-form-urlencoded; charset=UTF-8",
            },
            method: "post",
            url: "/IE_MES/workshop/routing_addEntity.shtml",
            data: this.$qs.stringify({
              "routingFormMap.process_route":this.addForm.process_route,
              "routingFormMap.process_route_desc":this.addForm.process_route_desc,
              "routingFormMap.state":this.addForm.state,
              "routingFormMap.allowpass":this.addForm.allowpass,
              "routingFormMap.data":this.addForm.data.toString(),
            }),
      }).then((res) => {
            if (res.data == "{\"result\":\"success\",\"score\":\"\"}") {
              this.getList();
              this.$refs['addFormRef'].resetFields();
              this.addDialogVisible=false;
              this.$message({
                type: "success",
                message: "添加成功!",
              });
            }
          });
    },
     // 编辑
    editDialog(row) {
      this.editForm = JSON.parse(JSON.stringify(row));
      this.editDialogVisible = true;
    },
    edit() {
      this.$axios({
            headers: {
              "Content-Type":
                "application/x-www-form-urlencoded; charset=UTF-8",
            },
            method: "post",
            url: "/IE_MES/workshop/routing_editEntity.shtml",
            data: this.$qs.stringify({
              "routingFormMap.id":this.editForm.id,
              "routingFormMap.process_route":this.editForm.process_route,
              "routingFormMap.process_route_desc":this.editForm.process_route_desc,
              "routingFormMap.state":this.editForm.state,
              "routingFormMap.allowpass":this.editForm.allowpass,
              "routingFormMap.data":this.editForm.data.toString(),
            }),
      }).then((res) => {
            if (res.data == "success") {
              this.getList();
              this.editDialogVisible=false;
              this.$message({
                type: "success",
                message: "编辑成功!",
              });
            }
          });
    },
    // 删除
    del(row) {
      this.$confirm("此操作将永久删除该内容, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios({
            headers: {
              "Content-Type":
                "application/x-www-form-urlencoded; charset=UTF-8",
            },
            method: "post",
            url: "/IE_MES/workshop/routing_deleteEntity.shtml?_t="+new Date(),
            data: this.$qs.stringify({
              ids:row.id
            }),
          }).then((res) => {
            if (res.data == "success") {
              this.getList();
              this.$message({
                type: "success",
                message: "删除成功!",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleSizeChange (newSize) {
      this.pageSize = newSize
      this.getList()
    },
    handleCurrentChange (newPage) {
      this.pageNow = newPage
      this.getList()
    },
    isOnline(online) {
      if (online == 1) {
        return '可用'
      } else {
        return '禁用'
      }
    },
    formatDate(data) {
        var date = new Date(data);
        var YY = date.getFullYear() + '-';
        var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
        var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
        var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
        var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
        return YY + MM + DD + " " + hh + mm + ss;
    },
  }
}
</script>

<style lang="less" scoped>
.el-form-item /deep/ .el-input__inner {
  padding-right: 420px !important;
}
</style>
